package com.xiaoqi.service.impl;

import com.alibaba.dubbo.config.annotation.Service;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.xiaoqi.dao.UserDao;
import com.xiaoqi.pojo.PageResult;
import com.xiaoqi.pojo.QueryPageBean;
import com.xiaoqi.pojo.User;
import com.xiaoqi.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * @author PC
 * creationTime: 2022/11/7 9:48
 */
@Service(interfaceClass = UserService.class)
@Transactional
public class UserServiceimpl implements UserService {

    @Autowired
    private UserDao userDao;

    /**
     * 查询所有用户
     * @return
     */
    @Override
    public PageResult findAll(QueryPageBean queryPageBean) {
        //开启分页
        PageHelper.startPage(queryPageBean.getCurrentPage(),queryPageBean.getPageSize());
        //开启分页后的第一条查询会被分页
        List<User> list = userDao.findAll(queryPageBean.getQueryString());
        //完善分页信息
        PageInfo<User> pageInfo = new PageInfo<>(list);
        return new PageResult(pageInfo.getTotal(),pageInfo.getList());
    }

    /**
     * 通过用户名查询用户的角色以及权限
     * @param username
     * @return
     */
    @Override
    public User findByName(String username) {
        return userDao.findByName(username);
    }

}
